/*
 * BCGenotype.h
 *
 *  Created on: 29/04/2013
 *      Author: agpardo
 */

#ifndef BCGENOTYPE_H_
#define BCGENOTYPE_H_

#include "Coord2d.h"
#include "BirthClinic/include/BCGene.h"
#include "BirthClinic/include/BCAgentWorldModel.h"

class BCGenotype{
	friend class BCAgent;

public:
	BCGenotype( BCAgentWorldModel* vm_, Coord2d mainCoords_);
	BCGenotype(BCAgentWorldModel* vm_, BCGenotype* parent1_, BCGenotype* parent2_, Coord2d mainCoords_);

	void sendGenotype();
	int getSize();
	int getGenotypeLength();
	Coord2d getCoordOfGene(int size_);
	void printGenotypeInfo();
	BCGene getGene(int index_);
	void addGene(BCGene gene_, Coord2d mainCoords_);

	void logGenotypeInfo();
	//void updateMutationStepSize();
	void updateMutationProb();

	double getMutationProbability();
	double getMutationStepSize();

private:
	int computeCoordinates(BCGene newGene_, Coord2d mainCoords_);
	bool isCollision(Coord2d coords_);
	Coord2d computeOffset(int parent_, int connectionDir_);
	bool collisionWithOtherRobots(Coord2d center_);
	bool isInsideBirthClinic(Coord2d center_);
	Coord2d getCorner(int id_, Coord2d center_, int width_, int height_);

	double _mutationProb;
	double _sigma;

protected:
	BCAgentWorldModel* _vm;

	std::vector<BCGene> _genome;
	std::map<int,Coord2d> _coords;

	std::map<int,Coord2d>::iterator _index;

	int checkOverlapping(Coord2d coord_);

};

typedef boost::shared_ptr<BCGenotype> BCGenotypePtr;


#endif /* BCGENOTYPE_H_ */
